﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Organized;

//console overlay screen where you can output things like framerate

namespace Game
{
    class Console : Component, I2DComponent
    {
        int frameRate;
        int frameCounter;
        TimeSpan elapsedTime;
        SpriteFont spriteFont;

        public virtual Rectangle Rectangle { get; set; }
      
        public Console(GameScreen Parent) : base(Parent) { 
    
            Rectangle = new Rectangle(0, 0, 200, 200);
            spriteFont = Engine.Content.Load<SpriteFont>("Content/Font");
           
        }
        
       
        
        public override void Update()
        {
            elapsedTime += Engine.GameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate = frameCounter;
                frameCounter = 0;
            } 
        }


        public override void Draw()
        {
            frameCounter++;
            DrawOverlayText();
        }

        void DrawOverlayText()
        {
            string text = string.Format("Frames per second: " + frameRate);
                                     

            Engine.SpriteBatch.Begin();
          
            Engine.SpriteBatch.DrawString(spriteFont, text, new Vector2(41, 41), Color.Black);
            Engine.SpriteBatch.DrawString(spriteFont, text, new Vector2(40, 40), Color.White);

            Engine.SpriteBatch.End();
        }
    }
}